Current Location: Home> Function Categories> date_create_from_format

date_create_from_format

Alias ​​for DateTime::createFromFormat - parsing datetime strings based on the given format
Name:date_create_from_format
Category:Date and time
Programming Language:php
One-line Description:Returns a new DateTime object formatted according to the specified format.

Definition and usage

The date_create_from_format() function returns a new DateTime object formatted according to the specified format.

Example

Returns a new DateTime object formatted according to the specified format:

 <?php
$date = date_create_from_format ( "jMY" , "25-Sep-2016" ) ;
?>

Try it yourself

grammar

 date_create_from_format ( format , time , timezone ) ;
parameter describe
format

Required. Specify the format to be used. The following characters can be used for the format parameter string:

  • d - What day of the month, with leading zero
  • j - What day of the month, without leading zeros
  • D - One day of the week (Mon - Sun)
  • I - One day of the week (Monday - Sunday)
  • S - English suffix for the day of the month (st, nd, rd, th)
  • F - Month Name (January - December)
  • M - Month Name (Jan - Dec)
  • m - Month (01 - 12)
  • n - Month (1 - 12)
  • Y - Year (e.g. 2013)
  • y - Year (e.g. 13)
  • a and A - am or pm
  • g - 12-hour system without leading zeros
  • h - 12-hour system with leading zeros
  • G - 24-hour system without leading zeros
  • H - 24-hour system with leading zero
  • i - points, with leading zero
  • s - seconds, with leading zeros
  • u - microseconds (up to six numbers)
  • e, O, P, and T - time zone identifiers
  • U - Number of seconds since the Unix Era
  • (Space)
  • # - One of the following delimiters: ;,:,/,.,, -, (,)
  • ? - A random byte
  • * - Random bytes until next separated/number
  • ! - Reset all fields to Unix Era
  • | - If all fields have not been parsed yet, reset all fields to Unix epoch
  • + - If present, trailing data in the string will cause a warning, not an error
time Required. Specify date/time string. NULL Indicates the current date/time.
timezone Optional. Specify the time zone. Default is the current time zone.
Similar Functions
Popular Articles